package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.TDownloadInfoVo;
import com.ruoyi.business.service.ITDownloadInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 常用下载Controller
 *
 * @author Tellsea
 * @date 2024-01-17
 */
@Api(tags = "常用下载Controller")
@RestController
@RequestMapping("/business/downloadInfo")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TDownloadInfoController extends BaseController {

    private final ITDownloadInfoService tDownloadInfoService;

    @ApiOperation("查询常用下载列表")
    //@PreAuthorize("@ss.hasPermi('business:downloadInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<TDownloadInfoVo> list(TDownloadInfoVo entity) {
        return tDownloadInfoService.queryList(entity);
    }

    @ApiOperation("查询常用下载所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TDownloadInfoVo entity) {
        return AjaxResult.success("查询成功", tDownloadInfoService.queryAll(entity));
    }

    @ApiOperation("导出常用下载列表")
    @PreAuthorize("@ss.hasPermi('business:downloadInfo:export')")
    @Log(title = "常用下载", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDownloadInfoVo entity) {
        List<TDownloadInfoVo> list = tDownloadInfoService.queryAll(entity);
        ExcelUtil<TDownloadInfoVo> util = new ExcelUtil<>(TDownloadInfoVo.class);
        util.exportExcel(response, list, "常用下载数据");
    }

    @ApiOperation("获取常用下载详细信息")
    //@PreAuthorize("@ss.hasPermi('business:downloadInfo:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tDownloadInfoService.queryById(id));
    }

    @ApiOperation("新增常用下载")
    @PreAuthorize("@ss.hasPermi('business:downloadInfo:add')")
    @Log(title = "常用下载", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TDownloadInfoVo entity) {
        return toAjax(tDownloadInfoService.save(entity));
    }

    @ApiOperation("修改常用下载")
    @PreAuthorize("@ss.hasPermi('business:downloadInfo:edit')")
    @Log(title = "常用下载", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TDownloadInfoVo entity) {
        return toAjax(tDownloadInfoService.updateById(entity));
    }

    @ApiOperation("删除常用下载")
    @PreAuthorize("@ss.hasPermi('business:downloadInfo:remove')")
    @Log(title = "常用下载", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tDownloadInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
